<?php
include("session.php");
include("config.php");

$row = prepare_edit(LEVEL_EDIT_USER, LEVEL_CREATE_USER, "edit_user.php", RLang("user"), "user", $db, "user_list.php");
if (!$row) {
   echo("error ". $row);
   exit();
}

$id = 0;
if ($row != 0)
   $id = $row['id'];

?>
<html>

<head>
   <title>Easy Time Tracker</title>
   <link rel="stylesheet" href="/timetracker.css" type="text/css" media="screen" />
</head>

<body>
   <div align="center">
      <h3>Benutzer bearbeiten</h3>
      <div class="BorderBox" align="center">
         <form method="post" action="write_user.php?id=<?php echo ($id); ?>">
            <table>
               <tr>
                  <td><?php ELang("name");?>:</td>
                  <td><input type="text" id="name" name="name" maxlength="50" <?php if ($id != 0) printf ("value='%s'", $row['name']); ?>></td>
               </tr>
               <tr>
                  <td><?php ELang("pword");?>:</td>
                  <td><input type="password" id="pass" name="pass" maxlength="50" minlength="10" <?php if ($id != 0 && strlen($row['pass']) > 0) printf ("value='%s'", DEFAULT_PWMASK); ?>></td>
               </tr>
               <tr>
                  <td><?php ELang("level");?>:</td>
                  <td><input type="number" id="level" name="level" min="0" max="100" <?php if ($id != 0) printf ("value='%u'",$row['level']); ?>></td>
               </tr>
               <tr>
                  <td><?php ELang("created");?>:</td>
                  <td> <?php if ($id != 0) echo ($row['created']); ?></td>
               </tr>
            </table>
            <button type="submit" value="<?php ELang("save");?>" class='tooltip'><img src='icons/22/document-save.png'><div class='rtooltiptext'>Speichern</div></button>
         <a href='user_list.php' class='tooltip'><img src='icons/22/edit-undo.png'><div class='rtooltiptext'><?php ELang("back");?></div></a>
         </form>
      </div>
      <p>
         <?php
         if (isset($_SESSION['msg'])) {
            if (isset($_SESSION['msgtype'])) {
               echo ("<div class=" . $_SESSION['msgtype'] . ">" . $_SESSION['msg'] . "</div>");
               unset($_SESSION['msgtype']);
            } else
               echo ("<div class=\"msg\" >" . $_SESSION['msg'] . "</div>");
            unset($_SESSION['msg']);
         }
         ?>
      </p>
   </div>
</body>

</html>